package com.itsq.controller.resources;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.base.BaseController;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.PageDepartmentDto;
import com.itsq.pojo.dto.PagePersonnelDto;
import com.itsq.pojo.dto.PersonnelDto;
import com.itsq.pojo.entity.Department;
import com.itsq.pojo.entity.Personnel;
import com.itsq.service.resources.PersonnelService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-01-30
 */
@RestController
@RequestMapping("/personnel")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "用户详情模块")
public class PersonnelController  extends BaseController {

    @Autowired
    private PersonnelService personnelService;

    @PostMapping("selPersonnelPageFront")
    @ApiOperation(value = "用户详情模块前台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Personnel>> selPersonnelPageFront(@RequestBody PagePersonnelDto pagePersonnelDto){
        Page<Personnel> PersonnelPage = personnelService.selPersonnelPageFront(pagePersonnelDto);
        return Response.success(PersonnelPage);
    }

    @PostMapping("selPersonnelPageAfter")
    @ApiOperation(value = "管理员——用户详情模块后台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Personnel>> selPersonnelPageAfter(@RequestBody PagePersonnelDto pagePersonnelDto){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        Page<Personnel> PersonnelPage = personnelService.selPersonnelPageAfter(pagePersonnelDto);
        return Response.success(PersonnelPage);
    }

    @PostMapping("insert")
    @ApiOperation(value = "管理员——用户详情模块添加", notes = "", httpMethod = "POST")
    public Response<PersonnelDto> insert(@RequestBody PersonnelDto personnel){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(personnelService.insert(personnel));
    }

    @PostMapping("insertFront")
    @ApiOperation(value = "用户详情模块前台添加", notes = "", httpMethod = "POST")
    public Response<PersonnelDto> insertFront(@RequestBody PersonnelDto personnel){
        return Response.success(personnelService.insert(personnel));
    }

    @PostMapping("update")
    @ApiOperation(value = "管理员——用户详情模块修改", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody Personnel personnel){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        return Response.success(personnelService.update(personnel));
    }

    @PostMapping("updateIsOk")
    @ApiOperation(value = "管理员——用户详情模块修改注册", notes = "", httpMethod = "POST")
    public Response<Integer> updateIsOk(@RequestBody Personnel personnel){
        return Response.success(personnelService.updateIsOk(personnel));
    }

    @PostMapping("selPersonnelByUserId")
    @ApiOperation(value = "用户详情模块根据用户编号查询", notes = "", httpMethod = "POST")
    public Response<PersonnelDto> selPersonnelByUserId(Integer userId){
        return Response.success(personnelService.selPersonnelByUserId(userId));
    }

    @PostMapping("delete")
    @ApiOperation(value = "用户详情模块删除", notes = "", httpMethod = "POST")
    public Response<Integer> delete(Integer id){
        return Response.success(personnelService.delete(id));
    }
}

